/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package psw;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

/**
 *
 * @author tabakkie
 */
public class GUI extends JFrame implements ActionListener
{
    private MenuPanel menuPanel;

    private StatusBar statusBar;
    private JPanel playPanel;

    private JPanel contentPane;

    private JPanel leftPanel  = new JPanel();
    private JPanel rightPanel = new JPanel();

    private JMenuBar myMenuBar;
    private AnswerBox[] answerBoxes = new AnswerBox[9];
    
    public void createGUI()
    {
        
        setTitle("PSW_TEST");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setResizable(false);
        
        // set Layouts
        leftPanel.setLayout(new GridLayout(11, 1));
        rightPanel.setLayout(null);

        contentPane = new JPanel();
        contentPane.setLayout(new CardLayout());

        // Create the contentpane of the Frame
        playPanel = new JPanel();
        playPanel.setLayout(new GridLayout(1, 2));
        contentPane.setPreferredSize(new Dimension(1024, 650));
        playPanel.setBackground(Color.LIGHT_GRAY);
        contentPane.add(playPanel, "playPanel");
        setContentPane(contentPane);

        // add JPanels to the JFrame
        playPanel.add(leftPanel);
        playPanel.add(rightPanel);

        pack();

        // add JPanels to the leftAnswerPanel
        createBoxes();

        // create menu items
        createMenu();

        // create the menuPanel for menu options
        menuPanel = new MenuPanel();
        menuPanel.create();
        contentPane.add(menuPanel, "menuPanel");

        pack();
        
        int contentPaneWidth = playPanel.getWidth();
        int contentPaneHeight = playPanel.getHeight();
        int rightPanelWidth = rightPanel.getWidth();
        int rightPanelHeight = rightPanel.getHeight();
        statusBar = new StatusBar(contentPaneWidth, contentPaneHeight);
        statusBar.setLocation(rightPanelWidth - statusBar.getWidth() - rightPanelHeight/40, rightPanelHeight - statusBar.getHeight() - rightPanelHeight/40);
        rightPanel.add(statusBar);

        setVisible(true);        
    }

    private void createBoxes()
    {
        for (int i = 0 ; i < answerBoxes.length ; i++)
        {
            answerBoxes[i] = new AnswerBox("Dit is antwoord " + (i+1), leftPanel.getHeight(), leftPanel.getWidth(), (i+1), this);
            leftPanel.add(answerBoxes[i]);
        }

            // create an empty panel for spacing
            leftPanel.add(new JPanel());
            leftPanel.add(new JButton("STOP"));
    }

    private void createMenu() {
        // Create all menu items
                    myMenuBar        = new JMenuBar();
        JMenuItem   myMenuItem       = new JMenuItem("Menu");

        myMenuItem.addActionListener(this);

        myMenuBar.add(myMenuItem);

        setJMenuBar(myMenuBar);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getActionCommand().equals("Menu")) {
            CardLayout cl = (CardLayout)(contentPane.getLayout());
            cl.show(contentPane, "menuPanel");
        }
    }
}